<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8"/>
    <title>  date test   </title>
</head>

<body>
<h2>
<?php
//    echo time();
    $submit_time='2018-6-11 21:30';
//    $db_time=1528721660;
    $db_time=mktime(21,30,0,6,11,2018);
    $submit_time=strtotime($submit_time);

    if($submit_time>$db_time){
        echo '提交时间>数据库时间';

    }
    elseif($submit_time==$db_time){
        echo '提交时间=数据库时间';

    }
    else{
        echo '提交时间<数据库时间';

    }





    $arr=[];
    $time=mktime(0,0,0,6,1,2018);		//将格式话时间转换为时间戳
    $month_size=date('t',$time);
    $week_num=date('N',$time);
    printf("<br/>这个月有%d天，6-1是星期%d<hr/>",$month_size,$week_num);

    for($tmp=$week_num,$day=1,$week=0;$week<5;$week++){
        for($w=0;$w<7;$w++) {
            if($w>=$week_num) {
                $week_num=0;
                $arr[$week][$w]=$day++;

                if($day>$month_size){       //超出这个月总天数就break
                    break;
                }
            }
            else{
                $arr[$week][$w]='';
            }
        }
    }




//    print_r($arr);
?>

    <table border="1" width="700">

        <tr>
            <th colspan="7"><?php echo date('Y-m-d',$time)?></th>
        </tr>

        <tr>
            <th>星期日</th>
            <th>星期一</th>
            <th>星期二</th>
            <th>星期三</th>
            <th>星期四</th>
            <th>星期五</th>
            <th>星期六</th>

        </tr>

        <?php
            $count=0;

            $tmp1=count($arr)-1;        //计算二维数组元素个数
            $tmp2=count($arr[$tmp1]);
            $num=$tmp1*7+$tmp2;
            unset($tmp1,$tmp2);

            for($i=0;$i<5;$i++)
            {
                echo '<tr>';
                for($t=0;$t<7;$t++){
                    $count++;
                    if($count>$num){
                        break;
                    }
                    echo '<th>'.$arr[$i][$t].'</th>';
                }

                echo '</tr>';
            }
        ?>

    </table>


</h2>
</body>








</html>

